package cc.yaomm.service.basic.mapper.user;

import cc.yaomm.common.basic.base.SuperMapper;
import cc.yaomm.common.biz.enums.OwnerTypeEnum;
import cc.yaomm.service.basic.entity.user.Roles;
import cc.yaomm.service.basic.mapper.user.po.RoleParamPO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Objects;

@Mapper
public interface RolesMapper extends SuperMapper<Roles> {

    /**
     * 根据用户ID查询拥有的权限
     *
     * @param ownerType
     * @param userId
     * @return
     */
    @Select("SELECT * FROM roles WHERE status = 1 AND owner_type = #{ownerType} AND  id IN (SELECT role_id FROM users_permissions_ref WHERE user_id = #{userId})")
    List<Roles> findByUserId(@Param("ownerType") OwnerTypeEnum ownerType, @Param("userId") Long userId);

}
